package com.piece.mall.config;

import com.piece.core.db.initializer.DataSourceScript;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component
public class InstallMallScript implements DataSourceScript {

    @Value(value = "${schema.mall.install:false}")
    private boolean enable;

    @Override
    public List<InputStream> loadScript() {
        if (enable) {
            List<InputStream> scripts = new ArrayList<>();
            scripts.add(getClass().getResourceAsStream("/sql/mall-pms-schema.sql"));
            scripts.add(getClass().getResourceAsStream("/sql/mall-oms-schema.sql"));
            scripts.add(getClass().getResourceAsStream("/sql/mall-sms-schema.sql"));
            return scripts;
        }

        return null;
    }

    @Override
    public Integer getIndex() {
        return Integer.MIN_VALUE;
    }

    @Override
    public String getScriptName() {
        return "执行 mall-pms-schema.sql / mall-oms-schema.sql / mall-sms-schema.sql 脚本文件";
    }
}
